/*     */ package dm.jdbc.rowset;
/*     */ 
/*     */ import dm.jdbc.dbaccess.Const;
/*     */ import dm.jdbc.dbaccess.DBError;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import java.io.Serializable;
/*     */ import java.sql.Blob;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ResourceBundle;
/*     */ 
/*     */ public class DmdbSerialBlob implements Serializable, Cloneable, Blob
/*     */ {
/*     */   private byte[] m_buffer;
/*     */   private long m_length;
/*     */   
/*     */   DmdbSerialBlob(byte[] buf)
/*     */   {
/*  20 */     if (buf != null) {
/*  21 */       this.m_length = buf.length;
/*     */     } else {
/*  23 */       this.m_length = 0L;
/*     */     }
/*  25 */     if (this.m_length <= 0L) {
/*  26 */       return;
/*     */     }
/*  28 */     this.m_buffer = new byte[(int)this.m_length];
/*  29 */     System.arraycopy(buf, 0, this.m_buffer, 0, (int)this.m_length);
/*     */   }
/*     */   
/*     */   DmdbSerialBlob(Blob blob) throws SQLException {
/*  33 */     if (blob == null) {
/*  34 */       return;
/*     */     }
/*  36 */     this.m_length = blob.length();
/*     */     
/*  38 */     if (this.m_length > 2147483647L) {
/*  39 */       throw new SQLException(Const.res.getString("error.dataTooLarge"));
/*     */     }
/*  41 */     this.m_buffer = blob.getBytes(1L, (int)this.m_length);
/*     */   }
/*     */   
/*     */   public long length() throws SQLException {
/*  45 */     return this.m_length;
/*     */   }
/*     */   
/*     */   public byte[] getBytes(long pos, int length) throws SQLException {
/*  49 */     if ((pos < 1L) || (length > this.m_length) || (pos + length > this.m_length)) {
/*  50 */       DBError.throwSQLException(6057);
/*     */     }
/*  52 */     byte[] dest = new byte[length];
/*  53 */     System.arraycopy(this.m_buffer, (int)pos - 1, dest, 0, length);
/*     */     
/*  55 */     return dest;
/*     */   }
/*     */   
/*     */   public InputStream getBinaryStream() throws SQLException {
/*  59 */     return new ByteArrayInputStream(this.m_buffer);
/*     */   }
/*     */   
/*     */   public long position(byte[] pattern, long start) throws SQLException {
/*  63 */     if ((pattern == null) || (start > this.m_length) || (start < 1L)) {
/*  64 */       return -1L;
/*     */     }
/*  66 */     long posRet = -1L;
/*  67 */     int ptnsize = pattern.length;
/*  68 */     for (int i = (int)(start - 1L); i < this.m_length;)
/*     */     {
/*  70 */       for (int j = 0; 
/*  71 */           j < ptnsize; j++) {
/*  72 */         if (this.m_buffer[i] != pattern[j])
/*     */           break;
/*  74 */         i++;
/*     */       }
/*     */       
/*  77 */       if (j == ptnsize) {
/*  78 */         posRet = i + 1;
/*  79 */         break;
/*     */       }
/*  81 */       j = 0;
/*  82 */       i++;
/*     */     }
/*     */     
/*     */ 
/*  86 */     return posRet;
/*     */   }
/*     */   
/*     */   public long position(Blob pattern, long start) throws SQLException {
/*  90 */     if ((pattern == null) || (start < 1L) || (start > this.m_length)) {
/*  91 */       return -1L;
/*     */     }
/*  93 */     return position(pattern.getBytes(0L, (int)pattern.length()), start);
/*     */   }
/*     */   
/*     */   public int setBytes(long pos, byte[] bytes) throws SQLException {
/*  97 */     DBError.throwUnsupportedSQLException();
/*     */     
/*  99 */     return -1;
/*     */   }
/*     */   
/*     */   public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
/*     */   {
/* 104 */     DBError.throwUnsupportedSQLException();
/*     */     
/* 106 */     return -1;
/*     */   }
/*     */   
/*     */   public OutputStream setBinaryStream(long pos) throws SQLException {
/* 110 */     DBError.throwUnsupportedSQLException();
/*     */     
/* 112 */     return null;
/*     */   }
/*     */   
/*     */   public void truncate(long len) throws SQLException
/*     */   {}
/*     */   
/*     */   public void free() throws SQLException
/*     */   {
/* 120 */     if ((this.m_buffer != null) || (this.m_length > 0L)) {
/* 121 */       this.m_buffer = null;
/* 122 */       this.m_length = 0L;
/*     */     }
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\rowset\DmdbSerialBlob.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       0.7.1
 */